<template>
  <div>
    <van-nav-bar class="top" title="账号注册" left-arrow @click-left="onClickLeft" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        placeholder="请输入账号"
        :rules="[{ required: true, message: '请输入账号' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        placeholder="请输入密码"
        :rules="[{ required: true, message: '请输入密码' }]"
      />
      <div style="margin: 16px">
        <van-button square block type="info" native-type="submit">注 册</van-button>
      </div>
      <router-link to="/login" style="color: #666">已有账号？去登录~</router-link>
    </van-form>
  </div>
</template>

<script>
import { register } from '@/api/user'

export default {
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    async onSubmit(value) {
      await register(value)
      // console.log(value)
      this.$toast.success('注册成功')
      this.$router.push('/login')
    },
    onClickLeft() {
      this.$router.push('/login')
    }
  }
}
</script>

<style></style>
